knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(rmarkdown)
library(flexdashboard)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(magrittr)
##
## 다음의 패키지를 부착합니다: 'magrittr'
##
## The following object is masked from 'package:purrr':
##
## set_names
##
## The following object is masked from 'package:tidyr':
##
## extract
library(DT)
library(plotly)
##
## 다음의 패키지를 부착합니다: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
본 보고서는 iris 데이터셋을 대상으로 기본 통계량,
변수 간 상관관계, 그리고 간단한 선형 회귀 분석을 수행한 결과를 정리한
것입니다.
iris 데이터셋은 붓꽃(Iris)의 종(Species)별로 꽃받침(Sepal)과
꽃잎(Petal)의 길이 및 너비를 측정한 데이터로, 각 변수 간의 관계를
분석하기에 적합한 예제 데이터입니다.
data_name <- params$dataset
data <- get(data_name)
# iris 데이터셋인 경우에만 분석 코드 실행
if(data_name == "iris"){
summary(data)
plot(data)
} else {
# iris 데이터셋이 아닐 경우: 아무 작업도 수행하지 않음
}
if(data_name == "iris"){
cor_matrix <- cor(data[, 1:4])
round(cor_matrix, 2)
} else {
# iris 데이터셋이 아닐 경우: 아무 작업도 수행하지 않음
}
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Sepal.Length 1.00 -0.12 0.87 0.82
## Sepal.Width -0.12 1.00 -0.43 -0.37
## Petal.Length 0.87 -0.43 1.00 0.96
## Petal.Width 0.82 -0.37 0.96 1.00
if(data_name == "iris"){
model <- lm(Petal.Length ~ Sepal.Length, data = data)
summary(model)
} else {
# iris 데이터셋이 아닐 경우: 아무 작업도 수행하지 않음
}
##
## Call:
## lm(formula = Petal.Length ~ Sepal.Length, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.47747 -0.59072 -0.00668 0.60484 2.49512
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -7.10144 0.50666 -14.02 <2e-16 ***
## Sepal.Length 1.85843 0.08586 21.65 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8678 on 148 degrees of freedom
## Multiple R-squared: 0.76, Adjusted R-squared: 0.7583
## F-statistic: 468.6 on 1 and 148 DF, p-value: < 2.2e-16
plotly를 사용하여 인터랙티브 산점도를
제공하고,DT 패키지를 통해 인터랙티브 데이터 테이블을
구현합니다.if(data_name == "iris"){
# iris 데이터셋에서 모든 종을 선택한 후, 상위 50행만 사용
selected_species <- unique(data$Species)
filtered_data <- data %>%
filter(Species %in% selected_species) %>%
head(50)
p <- ggplot(filtered_data, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point(size = 3, alpha = 0.8) +
labs(title = "Iris 데이터 산점도", x = "Sepal Length", y = "Petal Length") +
theme_minimal()
if (knitr::is_html_output()) {
ggplotly(p)
} else {
p
}
} else {
# iris 데이터셋이 아닐 경우: 아무 작업도 수행하지 않음
}
if(data_name == "iris"){
if (knitr::is_html_output()) {
DT::datatable(filtered_data)
} else {
knitr::kable(filtered_data)
}
} else {
# iris 데이터셋이 아닐 경우: 아무 작업도 수행하지 않음
}
기술 통계 및 데이터 탐색:
각 변수의 기본 통계량과 분포를 통해 iris 데이터셋의 전반적인 특성을
파악할 수 있었습니다.
상관관계 분석:
선형 회귀 분석: